<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="myModalLabel">添加新用户</h4>
        </div>
        <div class="modal-body">
           姓名：<input id="user_name" type="text" class="form-control" placeholder="请输入用户姓名">
            <br>
            Email：<input id="user_email" type="text" class="form-control" placeholder="请输入用户Email地址">
            <br>
            工号：<input id="employee_no" type="text" class="form-control" placeholder="请输入员工号">
            <br>
            手机：<input id="mobile" type="text" class="form-control" placeholder="请输入手机号码">
            <br>
            组织：<input id="unit_id" type="text" class="form-control" placeholder="请输入所属组织">
            <br>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭
            </button>
            <button id="save_new_user" type="button" class="btn btn-primary">保存</button>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal -->
<script language="JavaScript">
    $().ready(function(){
        $("#save_new_user").click(function(){
            if( do_validate() ){
                do_save_new_user();
            }
        })
    })
    function do_validate(){
        var user_name = $("#user_name").val();
        if( !user_name || user_name == null || user_name == "" ){
            alert("用户姓名不允许为空！");
            $("#user_name").focus();
            return false;
        }
        var user_email = $("#user_email").val();
        if( !user_email || user_email == null || user_email == "" ){
            alert("用户Email不允许为空！");
            $("#user_email").focus();
            return false;
        }
        var employee_no = $("#employee_no").val();
        if( !employee_no || employee_no == null || employee_no == "" ){
            alert("用户工号不允许为空！");
            $("#employee_no").focus();
            return false;
        }
        return true;
    }
    function do_save_new_user(){
        var url = "user";
        var data = {
            "user_name" : $("#user_name").val(),
            "user_email" : $("#user_email").val(),
            "employee_no" : $("#employee_no").val(),
            "mobile" : $("#mobile").val(),
            "unit_id" : $("#unit_id").val()
        }
        $.ajax( {
            type : "POST",
            url : url,
            dataType : "json",
            contentType: "application/json",
            data : JSON.stringify(data),
            error: function( XMLResponse ) {
                alert( XMLResponse.responseText )
            },
            success : function ( data ) {
                if ("success" != data.status) {
                    alert( data.message );
                }
                load_content_page("/face_recognition/main_user_list")
                $(function () { $('#myModal').modal('hide')});
            }
        } );
    }
</script>